<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Plupload: Test Uploader Events</title>

<!-- qunit -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-git.css" type="text/css" />
<script src="http://code.jquery.com/qunit/qunit-git.js"></script>

<!-- testrunner -->
<script src="../js/reporter.js"></script>
<script src="../scriptloader.js"></script>

<script type="text/javascript">

QUnit.config.reorder = false;
QUnit.config.testTimeout = 10000;

o.Env.swf_url = "../../js/flash/Moxie.swf";
o.Env.xap_url = "../../js/silverlight/Moxie.xap";

module("plupload.Uploader", {
	setup: function() {
		var options, up;

		$('#qunit-fixture').html('<div id="uploader" />');

		options = this.options = {
			browse_button: 'uploader',
			container: 'qunit-fixture',
			url: "Plupload/upload.php"
		};

		up = this.up = new plupload.Uploader(options);

		up.bind('PostInit', function() {
			QUnit.start();
		});

		QUnit.stop();
		up.init();
	},

	teardown: function() {
		this.up.destroy();
	}
});


test("Sequence of event handlers", function() {
	var up = this.up, seq = [];

	up.bind('SomeEvent', function() {
		seq.push(1);
	});

	up.bind('SomeEvent', function() {
		seq.push(2);
	});

	up.bind('SomeEvent', function() {
		seq.push(3);
	});

	up.bind('TestComplete', function() {
		deepEqual(seq, [1,2,3], "Event handlers run in sequence.");
	});

	up.trigger('SomeEvent');
	up.trigger('TestComplete');
});


test("Cancel consequent handlers", function() {
	var up = this.up, seq = [];

	up.bind('SomeEvent', function() {
		seq.push(1);
	});

	up.bind('SomeEvent', function() {
		seq.push(2);
		return false;
	});

	up.bind('SomeEvent', function() {
		seq.push(3);
	});

	up.bind('TestComplete', function() {
		deepEqual(seq, [1,2], "Consequent event handlers canceled by returning false.");
	});

	up.trigger('SomeEvent');
	up.trigger('TestComplete');
});

// test upload

</script>
</head>
<body>
	<h1 id="qunit-header">Plupload: Test Uploader</h1>
	<h2 id="qunit-banner"></h2>
	<h2 id="qunit-userAgent"></h2>
	<ol id="qunit-tests">
	</ol>
    <div id="qunit-fixture" style="position: relative; top: 0 !important; left: 0 !important; width: 100%; height: 9px;"></div>
</body>
</html>